package com.briup.corejava.day14;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;

/**
 * 测试泛型的相关内容
 */
public class Test1 {
    // 泛型方法
    public <A> A go(A a){
        return a;
    }
    public static void main(String[] args) {
        Circle<Integer,Double> c1 = new Circle<>(10,10,2.0);
        c1.show(5.0);
        c1.run(10);

        Circle<Integer,Integer> c3 = new Circle<>(10,10,5);
        c3.show(5);
        c3.run(10);

        Circle<String,Long> c2 = new Circle<>("20","30",4L);
        c2.show(10L);
        c2.run("20");

        System.out.println(new Test1().go("abc"));
        System.out.println(new Test1().go(10L));
        System.out.println(new Test1().go(20.0));

        Collection<?> c = new ArrayList<String>();
        c.add(null);

    }
}
// 泛型类
class Circle<T,E> implements Action<T>{
    @MyAnno("属性x")
    private T x;
    private T y;
    private E radius;

    public Circle(T x, T y, E radius) {
        this.x = x;
        this.y = y;
        this.radius = radius;
    }
    @MyAnno(value = "show方法",type = {MyAnno.Type.A,MyAnno.Type.B})
    public void show(E radius){
        if(radius instanceof Integer){
            int r = (Integer) radius;
            System.out.println(r*r*Math.PI);
        }else {
            System.out.println("("+x+", "+y+")");
        }
    }

    @Override
    public void run(T t) {
        System.out.println(t.getClass().getName());
    }
}
// 泛型接口
interface Action<T>{
    void run(T t);
}
